package com.atguigu.tingshu;


import org.redisson.api.RBloomFilter;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
import org.springframework.kafka.annotation.EnableKafkaStreams;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)//取消数据源自动配置
@EnableDiscoveryClient
@EnableFeignClients
@EnableAsync
@EnableElasticsearchRepositories(basePackages = "com.atguigu.tingshu.search.dao") // 包扫描
// @EnableScheduling // 开启定时任务
@EnableKafkaStreams//开启流式编程
public class ServiceSearchApplication {

    public static void main(String[] args) {
        SpringApplication.run(ServiceSearchApplication.class, args);
    }

    @Autowired
    private RedissonClient redissonClient;

    /**
     *布隆过滤器初始化
     */
    @Bean
    public RBloomFilter<Object> albumBloomFilter(){
        //构建布隆过滤器
        RBloomFilter<Object> albumBloomFilter =
                redissonClient.getBloomFilter("search_bloom_filter");
        //设置布隆过滤器的误差率: a.多少个请求中 b.发生误差的概率
        albumBloomFilter.tryInit(10000, 0.01);
        //返回
        return albumBloomFilter;
    }

    /**
     * 布隆过滤器的原理:
     * 布隆过滤器存在误差 误差不可避免只能无限趋近于0
     * 布隆过滤器只能新增
     * 存储:
     * 1.对于放入布隆过滤器的对象进行哈希计算(1次或者N次)
     * 2.计算的结果可以理解为一个二进制数字 所有位数都是0 但是计算后得到的位数是哪一位 哪一位就改为1
     * 查询:
     *  1.对于判断的值进行哈希计算(1次或者N次)
     *  2.根据计算的结果来判断是否存在
     */

}
